﻿/* **********************************************************************************
 *
 * Copyright (c) WickedFlame Projects. All rights reserved.
 *
 * This source code is subject to terms and conditions of the Microsoft Reciprocal License
 * for WickedFlame. A copy of the license can be found in the License.html file
 * at the root of this distribution. 
 * By using this source code in any fashion, you are agreeing to be bound by
 * the terms of the Microsoft Reciprocal License for WickedFlame.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * **********************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Gencode.Controls.CollapsibleControl
{
    [ToolboxBitmap(typeof(ResFinder), "Gencode.Controls.Collapse.ico")]
	[ToolboxItem(true)]
	public partial class CollapsibleControl : UserControl
	{
        CollapsibleControlCollection m_nodes;
        internal event CollapsibelControlResizeEventHandler ControlResize;

		public CollapsibleControl()
		{
			InitializeComponent();
            m_nodes = new CollapsibleControlCollection(this);
		}

        public CollapsibleControlCollection Nodes
        {
            get
            {
                if (m_nodes == null)
                    m_nodes = new CollapsibleControlCollection(this);
                return m_nodes;
            }
        }

        internal void Panel_Resize(object sender, EventArgs e)
        {
			if (ControlResize != null)
				ControlResize(this, new CollapsibelControlResizeEventArgs(this.Width, this.ClientSize.Width));
        }

        internal void ListHeaderStateChanged(object sender, ListHeaderStateChangedEventArgs e)
        {
            Panel_Resize(null, new EventArgs());
        }
	}

    internal delegate void CollapsibelControlResizeEventHandler(object sender, CollapsibelControlResizeEventArgs e);
    
    internal class CollapsibelControlResizeEventArgs : EventArgs
    {
        int parentWidth;
		int parentClientWidth;

        public CollapsibelControlResizeEventArgs(int parentWidth, int parentClientWidth)
            : base()
        {
            this.parentWidth = parentWidth;
			this.parentClientWidth = parentClientWidth;
        }

        public int ParentWidth
        {
            get
            {
                return (parentWidth);
            }
        }

		public int ParentClientWidth
		{
			get
			{
				return parentClientWidth;
			}
		}
    }
}
